package com.it.you.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class People {

    private String name;

    private int age;

    private Date birthDate;

    private String address;


    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final People that = (People) o;
        return getGroupByKey(this).equals(getGroupByKey(that));
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.name, this.age);
    }

    public String getGroupByKey(People peo) {
        StringBuffer keyBuffer = new StringBuffer();
        if (peo.ageEq18()) {
            keyBuffer.append(peo.getName());
        } else {
            keyBuffer.append(peo.getName()).append(",")
                    .append(peo.getAge()).append(",")
                    .append(peo.getAddress());
        }
        return keyBuffer.toString();
    }

    public boolean ageEq18() {
        return this.getAge() == 18;
    }


}
